import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;

public class MyThreadPool {
    //设置任务队列
        BlockingDeque<Runnable> queue=new LinkedBlockingDeque<>();
   //任务放到队列
   public void submit(Runnable runnable) throws InterruptedException {
       queue.put(runnable);
   }
   //线程执行
    public MyThreadPool(int n) throws InterruptedException {
       for (int i=0;i<n;i++){
           Thread t=new Thread(()->{
               try {
                  Runnable runnable = queue.take();
                   runnable.run();
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           });
           t.start();
       }
    }
}
class M{
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool myThreadPool=new MyThreadPool(4);
        for (int i=0;i<100;i++){
            int id=i;
            myThreadPool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("i="+id);
                }
            });
        }

    }
}
